<?php
namespace app\index\controller;

use app\admin\controller\Comment;

class Index extends Base
{
    public function index()
    {
        $where = [];
        if (input("?id")){
            $where = [
              'cate_id' => input('id')
            ];
        }
        $articles = model('article')->where($where)->order("create_time", "desc")->paginate(5);
        $this->assign("articles", $articles);
        return view();
    }

    //登录
    public function login(){
        if (request()->isAjax()){
            $data = [
                "username" => input('post.username'),
                "password" => input('post.password'),
                "verify" => input('post.verify')
            ];
            $result = model('Member')->login($data);
            if ($result == 1){
                $this->success('登陆成功', 'index/index/index');
            }else{
                $this->error($result);
            }
        }
        return view();
    }

    //注册
    public function register(){
        if (request()->isAjax()){
            $data = [
                "username" => input('post.username'),
                "password" => input('post.password'),
                "conpass" => input('post.conpass'),
                'nickname' => input('post.nickname'),
                "email" => input('post.email')
            ];
            $result = model('member')->register($data);
            if ($result == 1){
                $this->success("注册成功", 'index/index/login');
            }else{
                $this->error($result);
            }
        }
        return view();
    }
}
